# 
 #  Licensed to the Apache Software Foundation (ASF) under one
 #  or more contributor license agreements. See the NOTICE file
 #  distributed with this work for additional information
 #  regarding copyright ownership. The ASF licenses this file
 #  to you under the Apache License, Version 2.0 (the
 #  "License"); you may not use this file except in compliance
 #  with the License. You may obtain a copy of the License at
 # 
 #      http://www.apache.org/licenses/LICENSE-2.0
 # 
 #  Unless required by applicable law or agreed to in writing,
 #  software distributed under the License is distributed on an
 #  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 #  KIND, either express or implied. See the License for the
 #  specific language governing permissions and limitations under the License.
 #  
 # 
 
from google.appengine.ext import db;

class Directory(db.Model):
	id = db.StringProperty();
	directory_name = db.StringProperty(multiline=False);

	@classmethod
	def get(cls, name):
		q = db.Query(Directory)
		q.filter('directory_name = ', name)
		return q.get()
	@classmethod
	def is_exist(cls, directory_name):
		resultSet = db.GqlQuery("SELECT * FROM Directory WHERE directory_name = '" + directory_name + "'");
		for recordSet in resultSet:
			if recordSet.id:
				return True;
				break;
		return False;

class File(db.Model):
	id = db.StringProperty();
	directory_name = db.StringProperty();
	file_name = db.StringProperty(multiline=False);
	content = db.StringProperty(multiline=True);
	created_on = db.DateTimeProperty(auto_now_add=True);
	modified_on = db.DateTimeProperty(auto_now_add=True);
	accessed_on = db.DateTimeProperty(auto_now_add=True);
	access = db.BooleanProperty(required=False, default=False)
	tmp = db.BooleanProperty(required=False, default=False)

	@classmethod
	def is_exist(cls, directory_name, file_name):
		resultSet = db.GqlQuery("SELECT * FROM File WHERE directory_name = '" + directory_name + "' AND file_name = '" + file_name + "'");
		for recordSet in resultSet:
			if recordSet.id:
				return recordSet.id;
				break;
		return False;
	
	@classmethod
	def get(cls, directory_name, file_name):
		q = db.Query(File);
		q.filter('directory_name = ', directory_name);
		q.filter('file_name = ', file_name);
		return q.get();